<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String appPath = request.getContextPath();
%>
<div>
	<div id="order_content_div">
		<div class="tjddtit" style="margin-top: 40px;">
			<h1>商品信息</h1>
		</div>
		<c:set var="goodsTotal" value="0" />
		<c:set var="goodsAmount" value="0" />
		<c:set var="pointssAmount" value="0" />
		<c:set var="newStorageFlag" value="0"></c:set>
		<input type="hidden" id="noneedExpressCode" value="${noneedExpressCode}"/>
		<c:forEach items="${cartItemsGroupByStorageId}" var="cartItems" varStatus="storageStatus">
			<table width="200" border="0" class="tjdd2">
			<c:if test="${newStorageFlag==0}">
				<tr class="tjdd3">
					<th scope="col" width="70%">商品</th>
					<th scope="col" width="10%">单价</th>
					<th scope="col" width="10%">数量</th>
					<th scope="col" width="10%">小计</th>
				</tr>
				<c:set var="newStorageFlag" value="1"></c:set>
			</c:if>
				<tr>
					<td colspan="4">
						<div class="tjddtit" style="border: none; margin-top: 20px;">
							<h1>${cartItems.value[0].goods.storage.name}</h1>
						</div>
					</td>
				</tr>
				<c:set var="storageGoodsTotal" value="0"></c:set>
				<c:set var="storageGoodsAmount" value="0"></c:set>
				<c:set var="storageGoodsPointsAmount" value="0"></c:set>
				<c:forEach items="${cartItems.value}" var="cartIem" varStatus="cartItemStatus">
					<tr>
						<td class="tjdd4"  width="70%" style="line-height: 100px;"><img src="${cartIem.goodsImage}" style="width: 100px; height: 100px; margin: 10px; float: left;" />
						 <a href="javascript:void(0);">${cartIem.goodsName}</a></td>
						<td class="tjdd4" width="10%" style="text-align: center;">
							<c:choose>
								<c:when test="${'1'==pointBuyFlag}">
											积分：${cartIem.sku.points}
										</c:when>
								<c:otherwise>
											￥<fmt:formatNumber value="${cartIem.goodsPrice/100}" pattern="0.00" />
								</c:otherwise>
							</c:choose> 
						</td>
						<td class="tjdd4" width="10%" style="text-align: center;">${cartIem.goodsNum}</td>
						<td class="tjdd4" width="10%" style="text-align: center;"><b>
							<c:choose>
								<c:when test="${'1'==pointBuyFlag}">
											积分：${cartIem.sku.points*cartIem.goodsNum}
										</c:when>
								<c:otherwise>
									￥<fmt:formatNumber value="${cartIem.goodsPrice*cartIem.goodsNum/100}" pattern="0.00" />
								</c:otherwise>
							</c:choose> 
						
						</b></td>
					</tr>
					<c:set var="storageGoodsTotal" value="${storageGoodsTotal+cartIem.goodsNum}"></c:set>
					<c:set var="storageGoodsAmount" value="${storageGoodsAmount+cartIem.goodsPrice*cartIem.goodsNum}"></c:set>
					<c:set var="storageGoodsPointsAmount" value="${storageGoodsPointsAmount+cartIem.sku.points*cartIem.goodsNum}"></c:set>
					<input type="hidden" name="storageOrderInfoList[${storageStatus.index}].carts[${cartItemStatus.index}].skuId" value="${cartIem.sku.id}" />
					<input type="hidden" name="storageOrderInfoList[${storageStatus.index}].carts[${cartItemStatus.index}].num" value="${cartIem.goodsNum}" />
				</c:forEach>
				</table>
			<input type="hidden" name="storageOrderInfoList[${storageStatus.index}].storageId" value='${fn:replace(cartItems.key, "storage","")}' />
			<div class="tjdd5">
				<h2>
					共${storageGoodsTotal}件
					<c:choose>
						<c:when test="${'1'==pointBuyFlag}">
							积分：${storageGoodsPointsAmount}
						</c:when>
						<c:otherwise>
							商品金额：￥<fmt:formatNumber value="${storageGoodsAmount/100}" pattern="0.00" />
						</c:otherwise>
					</c:choose>  
				</h2>
			</div>
			<div class="tjdd5">
				<c:set value='${fn:replace(cartItems.key, "storage", "storageExpress")}' var='storageExpressKey' />
				<!-- 仓库快递 -->
				<select class="weui_select express-select" name="storageOrderInfoList[${storageStatus.index}].expressId">
					<c:forEach items="${expressGroupByStorageId[storageExpressKey]}" var="express">
						<option value="${express[1]}" code="${express[2]}">${express[3]}</option>
					</c:forEach>
				</select> <label>选择物流：</label>
			</div>
			<!-- 买家留言 -->
			<div class="order-remark">
				<label class="remark-name" >给卖家留言：</label>
				<div class="remark-detail">
					<textarea maxlength="120" class="remark-input" placeholder="选填:对本次交易的说明(建议填写已和卖家协商一致的内容)" name="storageOrderInfoList[${storageStatus.index}].remark"></textarea>
					<div></div>
					<span>
					0/120
					</span>
				</div>
			</div>
			<c:set var="goodsTotal" value="${goodsTotal+storageGoodsTotal}" />
			<c:set var="goodsAmount" value="${goodsAmount+storageGoodsAmount}" />
			<c:set var="goodsPoints" value="${goodsPoints+storageGoodsPointsAmount}" />
		</c:forEach>
		<!--  代金券 -->
        <div id="voucher_container_div" style="margin: 10px ;" >
	        <c:if test="${voucherList!=null&&fn:length(voucherList)>0}">
	        	<div class="tjddtit" style="margin-top: 40px;">
					<h1>可用代金券</h1>
		        	<input type="hidden" value="" name="voucherId" id="voucherId"/>
				</div>
	        	<%--
	        	<input type="radio" name ="voucherId" value="0"  checked /> 不使用代金券
        		<input type="radio" name ="voucherId"  value="${voucher.id}" /> ${voucher.name}
	        	 --%>
	        	<c:forEach items="${voucherList}" var ="voucher">
	        		<div class="c-msg voucher-div" vid="${voucher.id}">
						<div class="voucher-top voucher-top-bg"></div>
						<div class="item-selected-cancel hide">取消勾选</div>
						<div class="voucher-price">
							<span>￥<fmt:formatNumber value="${(voucher.price-voucher.price%100)/100}" type="NUMBER" ></fmt:formatNumber></span>
						</div>
						<div class="voucher-limit">
							<span> 满<fmt:formatNumber value="${(voucher.limitMoney-voucher.limitMoney%100)/100}" type="NUMBER" ></fmt:formatNumber></span>
						</div>
						<div class="voucher-time">
							<span>有效期至<fmt:formatDate value="${voucher.endDate}" pattern="yyyy-MM-dd"></fmt:formatDate> </span>
						</div>
					</div>
				</c:forEach>
	        </c:if>
		</div>
		<div class="clear" style="clear: both;"></div>
        <!-- 满赠和满减 -->
        <div id="activity_div" style="margin: 10px ;">
	        <c:if test="${activityInfoList!=null&&fn:length(activityInfoList)>0}">
	        	<div class="tjddtit">
					<h1>优惠活动</h1>
				</div>
				<div style="margin: 10px;float: right;" >
					<input type="hidden" name="activityId" id="activityId" />
					<select style="width: 200px" onchange="getActivityInfo(this)">
						<option value="-1" selected="selected">不使用活动优惠</option>
			        	<c:forEach items="${activityInfoList}" var ="activity">
							<option value="${activity[0]},${activity[3]}" >${activity[1]}</option>
			        	</c:forEach>
					</select>
				</div>
	        </c:if>
        </div>
        <div class="clear" style="clear: both;margin-bottom: 10px"></div>
		<div id="order_gift_div" style="margin-left: 10px">
		</div>
		<div class="tjdd6 right_info">
			<ul >
				<li>共${goodsTotal}件商品，
					<c:choose>
						<c:when test="${'1'==pointBuyFlag}">
							积分：${goodsPoints}
						</c:when>
						<c:otherwise>
							商品总金额：￥<fmt:formatNumber value="${goodsAmount/100}" pattern="0.00" />
						</c:otherwise>
					</c:choose>  
				</li>
				<!-- 
							 <li>使用代金券：￥0.00</li>
					         <li>优惠金额：￥0.00</li>
					         <li>运费：￥0.00</li>
					          -->
				<li>
					<c:choose>
						<c:when test="${'1'==pointBuyFlag}">
							消费积分：${goodsPoints}
							<input type="hidden" id="consumePoints" value="${goodsPoints}"/>
							<input type="hidden" id="userPoints" value="${userPoints}"/>
						</c:when>
						<c:otherwise>
							实付总额：<span>￥<fmt:formatNumber value="${goodsAmount/100}" pattern="0.00" /></span>
						</c:otherwise>
					</c:choose> 
				</li>
				<li><input type="button" id="submit_order" style="cursor: pointer;" value="提交订单" /></li>
			</ul>
		</div>
		<input type="hidden" name="token" id="token-input" />
		 <input type="hidden" value="${synchronizeCookieStr}" id="synchronizeCookieStr" />
		 <input type="hidden" name="pointBuyFlag" id="pointBuyFlag" value="${pointBuyFlag}" />
	</div>
	<!-- 收货地址 -->
	<div id="address_div">
		<div id="confirm_address_div"  style="display: none" >
			<div class="tjddtit">
				<h1>收货地址</h1>
			</div>
			<div class="tjdd1" >
				<p id="address_info"> </p>
			</div>
		</div>
		<div id="choose_address_div">
		<div class="tjddtit">
			<h1>选择收货地址：</h1>
			<a href="javascript:toAdd();" class="tc" >+ 添加新地址</a>
		</div>
		<c:if test="${addressList==null||fn:length(addressList)==0}">
			<div class="tjdd1">
				<input type="hidden" id="addressIsNull" value="1" />
				您还没有添加地址，请新增地址！
			</div>
		</c:if>
		<div>
			<c:forEach items="${addressList}" var="address" varStatus="addressIndex">
				<div class="tjdd1 ${addressIndex.index>2?'more_address':''}" >
					<input type="radio" name="addressId" value="${address.id}" ${address.isDefault == '1'?'checked="checked"':''} />
					<p>${address.province!=null?address.province.name:''}${address.city!=null&&address.city.name!='其他'?address.city.name:''}${address.county!=null&&address.county.name!='其他'?address.county.name:''} ${address.address }</p>
					<c:choose>
						<c:when test="${address.isDefault == '1'}">
							<span>默认地址</span> 
						</c:when>
						<c:otherwise>
							<a href="javascript:setDefault('${address.id }');" class="td1a">设为默认地址</a>
						</c:otherwise>
					</c:choose>
					<a href="javascript:edit('${address.id }')" >编辑</a> 
					<c:if test="${address.isDefault == '0' }"> <a href="javascript:del('${address.id }');" class="td1a">删除</a> </c:if>
				</div>
			</c:forEach>
		</div>
		<div class="tjddtit" style="border: none;">
			<c:if test="${addressList!=null&&fn:length(addressList)>3}">
				<a href="javascript:void(0);"  id="show_more" onclick="javascript:showMoreAddress();" >更多地址 &gt;&gt;</a>
				<a href="javascript:void(0);"  id="hide_more" onclick="javascript:hideMoreAddress();" style="display: none">收起 &gt;&gt;</a>
			</c:if>
		</div>
		<div class="tjddtit2">
			<input type="button" name="" onclick="javascript:confirmAddress();" value="确认收货地址"  id="confirm_address" style="cursor: pointer;"/> <a href="<%=appPath%>/cart/list.htm" >&lt;&lt;返回购物车修改</a>
		</div>
		</div>
		<div class="popup2" id="popup1"></div>
	</div>
</div>
